<blockquote class="layui-elem-quote">鼠标移开，自动保存更改.</blockquote>
<div class="layui-tab">
  <ul class="layui-tab-title">
    <li class="layui-this">网站设置</li>
    <li>网页碎片</li>
    <li>业务配置</li>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
        <form class="layui-form" action="">
            <{volist name='list' id='v'}>
            <{if $v['cat']==0}>

            <{if $v['type']=='input'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <input type="text" name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" autocomplete="off" class="layui-input" value="<{$v['value']}>">
            </div>
          </div>

            <{elseif $v['type']=='text'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                <textarea name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
            </div>
          </div>

            <{elseif $v['type']=='html'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <textarea name="<{$v['id']}>" id="edit<{$v['id']}>" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
              <button class="layui-btn" id="editbtn<{$v['id']}>">更新编辑器</button>
            </div>
          </div>

            <{elseif $v['type']=='select'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <select name="<{$v['id']}>" lay-filter="filter" onchange="up(this)" placeholder="<{$v['placeholder']}>" >
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                <option value="<{$val}>" <{if $v['value']==$val}>selected<{/if}>><{$val}></option>
                  <{/volist}>
              </select>
            </div>
          </div>

            <{elseif $v['type']=='checkbox'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                    <input type="checkbox" name="<{$v['id']}>" value="<{$val}>" title="<{$val}>"  <{if $v['value'] and in_array($val, explode("|",$v['value'])) }> checked <{/if}> lay-filter="filter">
                  <{/volist}>
            </div>
          </div>

            <{elseif $v['type']=='pic'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <button type="button" class="layui-btn layui-btn-default myupload" name="<{$v['id']}>"><i class="layui-icon"></i><{$v['placeholder']}></button>
                <img id="img<{$v['id']}>" src="<{:pic($v['value'])}>" height="100" />
            </div>
          </div>
            <{/if}>


            <{/if}>
            <{/volist}>
        </form>

    </div>
    <div class="layui-tab-item">
        <form class="layui-form" action="">
            <{volist name='list' id='v'}>
            <{if $v['cat']==1}>

            <{if $v['type']=='input'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <input type="text" name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" autocomplete="off" class="layui-input" value="<{$v['value']}>">
            </div>
          </div>

            <{elseif $v['type']=='text'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                <textarea name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
            </div>
          </div>

            <{elseif $v['type']=='html'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <textarea name="<{$v['id']}>" id="edit<{$v['id']}>" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
              <button class="layui-btn" id="editbtn<{$v['id']}>">更新编辑器</button>
            </div>
          </div>

            <{elseif $v['type']=='select'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <select name="<{$v['id']}>" lay-filter="filter" onchange="up(this)" placeholder="<{$v['placeholder']}>" >
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                <option value="<{$val}>" <{if $v['value']==$val}>selected<{/if}>><{$val}></option>
                  <{/volist}>
              </select>
            </div>
          </div>

            <{elseif $v['type']=='checkbox'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                    <input type="checkbox" name="<{$v['id']}>" value="<{$val}>" title="<{$val}>"  <{if $v['value'] and in_array($val, explode("|",$v['value'])) }> checked <{/if}> lay-filter="filter">
                  <{/volist}>
            </div>
          </div>

            <{elseif $v['type']=='pic'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <button type="button" class="layui-btn layui-btn-default myupload" name="<{$v['id']}>"><i class="layui-icon"></i><{$v['placeholder']}></button>
                <img id="img<{$v['id']}>" src="<{:pic($v['value'])}>" height="100" />
            </div>
          </div>
            <{/if}>


            <{/if}>
            <{/volist}>
        </form>
    </div>
    <div class="layui-tab-item">
        <form class="layui-form" action="">
            <{volist name='list' id='v'}>
            <{if $v['cat']==2}>

            <{if $v['type']=='input'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <input type="text" name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" autocomplete="off" class="layui-input" value="<{$v['value']}>">
            </div>
          </div>

            <{elseif $v['type']=='text'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                <textarea name="<{$v['id']}>" onchange="up(this)" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
            </div>
          </div>

            <{elseif $v['type']=='html'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <textarea name="<{$v['id']}>" id="edit<{$v['id']}>" placeholder="<{$v['placeholder']}>" class="layui-textarea"><{$v['value']}></textarea>
              <button class="layui-btn" id="editbtn<{$v['id']}>">更新编辑器</button>
            </div>
          </div>

            <{elseif $v['type']=='select'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <select name="<{$v['id']}>" lay-filter="filter" onchange="up(this)" placeholder="<{$v['placeholder']}>" >
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                <option value="<{$val}>" <{if $v['value']==$val}>selected<{/if}>><{$val}></option>
                  <{/volist}>
              </select>
            </div>
          </div>

            <{elseif $v['type']=='checkbox'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
                  <{php}>$svalue = explode("|",$v['selectvalue']);<{/php}>
                  <{volist name='svalue' id="val"}>
                    <input type="checkbox" name="<{$v['id']}>" value="<{$val}>" title="<{$val}>"  <{if $v['value'] and in_array($val, explode("|",$v['value'])) }> checked <{/if}> lay-filter="filter">
                  <{/volist}>
            </div>
          </div>

            <{elseif $v['type']=='pic'}>
          <div class="layui-form-item">
            <label class="layui-form-label"><{$v['description']}></label>
            <div class="layui-input-block">
              <button type="button" class="layui-btn layui-btn-default myupload" name="<{$v['id']}>"><i class="layui-icon"></i><{$v['placeholder']}></button>
                <img id="img<{$v['id']}>" src="<{:pic($v['value'])}>" height="100" />
            </div>
          </div>
            <{/if}>


            <{/if}>
            <{/volist}>
        </form>
    </div>
  </div>
</div>
<script>
$().ready(function(){

    //编辑框
    $(".layui-textarea").each(function(i,e){
      var id = $(e).attr('name');
      var index = layui.layedit.build('edit'+id,{uploadImage:{url: '<{:url('api/upimg')}>', type: 'post'},height:180});

      //提交编辑器内容
      $("#editbtn"+id).click(function(){
          var value = layui.layedit.getContent(index);
          $.ajax({
            url:'<{:url('sys/upinput')}>',
            method:'post',
            dataType:'json',
            data:{id:id,value:value},
            success:function(rs){
              _action(rs)
            }
          });

      });
    });


    //美化下拉
    layui.form.render('select');
    //美化多选
    layui.form.render('checkbox');

    //上传图片
    layui.upload.render({
        url:'/api/upimg',
        elem: '.myupload',
        accept:'images',
        before:function(obj){
          layui.layer.load(1, {shade: [0.1,'#fff']});
        },
        done:function(rs,index,upload){
            layui.layer.closeAll('loading');
            if(rs.code){
              layui.layer.msg(rs.msg,{icon:5});
            }else{
              var id= $(this.item).attr('name');
              var value = rs.data.src;
              $.ajax({
                url:'<{:url('sys/upinput')}>',
                method:'post',
                dataType:'json',
                data:{id:id,value:value},
                success:function(rs){
                  _action(rs)
                }
              });
              $("#img"+id).attr('src',rs.data.src);
            }
        },
        error:function(index,upload){
            layui.layer.closeAll('loading');
        }
      });


    //监听checkbox
    layui.form.on('checkbox(filter)', function(data){
      var id= $(data.elem).attr('name');
      var value = data.value;
      $.ajax({
        url:'<{:url('sys/upcheckbox')}>',
        method:'post',
        dataType:'json',
        data:{id:id,value:value},
        success:function(rs){
          _action(rs)
        }
      });
    });
    //监听select
    layui.form.on('select(filter)', function(data){
      var id= $(data.elem).attr('name');
      var value = data.value;
      $.ajax({
        url:'<{:url('sys/upinput')}>',
        method:'post',
        dataType:'json',
        data:{id:id,value:value},
        success:function(rs){
          _action(rs)
        }
      });
    });
});

//更新
function up(e){
  var id= $(e).attr('name');
  var value = $(e).val();
  $.ajax({
    url:'<{:url('sys/upinput')}>',
    method:'post',
    dataType:'json',
    data:{id:id,value:value},
    success:function(rs){
      _action(rs)
    }
  });
}
</script>
